<template>
	<view>
		<view>
			用户当前纬度{{latitude}}
		</view>
		<view>
			用户当前纬度{{longitude}}
		</view>
		<view>
			所在城市{{userCity}}
		</view>
		<view>
			用户详细地址{{userDetailAddress}}
		</view>
		<view class="mapBlock">
			<map class="mapBlock" latitude="30.37559" longitude="114.32168" show-location="true"></map>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				latitude:"定位中",
				longitude:"定位中",
				userDetailAddress:"定位中",
				userCity:"定位中"
			}
		},
		onLoad(){
			const self=this;
			setTimeout(()=>{
			uni.getLocation({
				type:'gcj02',
				success:function(res){
					console.log('当前位置的经度：'+ res.longitude);
					console.log('当前位置的纬度：'+ res.latitude);
					self.longitude=res.longitude;
					self.latitude=res.latitude;
					
					const self2=self;
					uni.request({
						// url:"http://restapi.amap.com/v3/geocode/regeo?key=58ae213b8ebbb1989b39eb59075a4212&location=116.481488,39.990464",
						url:"http://restapi.amap.com/v3/geocode/regeo?",
						data:{
							key:'58ae213b8ebbb1989b39eb59075a4212',
							location:res.longitude+","+res.latitude
						},
						success(res){
							console.log("高德地图api返回结果：",res)
							console.log("用户地址："+res.data.regeocode.formatted_address)
							self2.userDetailAddress=res.data.regeocode.formatted_address
							self2.userCity=res.data.regeocode.addressComponent.city
						}
					})
				}
			});
		},3000)
		}
	}
</script>

<style lang="less">
	.mapBlock{
		width: 100%;
		background-color: black;
	}
</style>
